package com.haibei.activity;

import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.os.AsyncTask;
import android.os.Bundle;

import com.common.BaseActivity;
import com.umeng.analytics.MobclickAgent;

public class BaseHaibeiActivity extends BaseActivity {

	private AsyncTask mTaskRunning;
	private boolean needReCreate = false;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		getmProgressDialog().setOnCancelListener(new OnCancelListener() {
			@Override
			public void onCancel(DialogInterface dialog) {
				if (null != mTaskRunning && !mTaskRunning.isCancelled()) {
					mTaskRunning.cancel(true);
				}
			}
		});
	}

	public void showProgressDialogWithTask(AsyncTask runingTask) {
		mTaskRunning = runingTask;
		showProgressDialog();
	}

	@Override
	protected void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);
	}

	@Override
	protected void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}

	// public void onResume() {
	// super.onResume();
	// MobclickAgent.onResume(this);
	// }
	//
	// public void onPause() {
	// super.onPause();
	// MobclickAgent.onPause(this);
	// }

	// @Override
	// protected void onPause() {
	// super.onPause();
	// }
	//
	// @Override
	// protected void onResume() {
	// super.onResume();
	// }

	public void showProgressDialog() {
		Dialog dlg = getmProgressDialog();
		if (null != dlg) {
			dlg.show();
		} else {
			crateDialog();
			getmProgressDialog().show();
		}
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		getmProgressDialog().dismiss();
	}

	public void hideProgressDialogWithTask() {
		if (null != mTaskRunning && !mTaskRunning.isCancelled()) {
			mTaskRunning.cancel(true);
		}
		hideProgressDialog();
	}
}
